package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Remolqueshipoteca;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class RemolqueshipotecaPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Remolqueshipoteca> list;

public RemolqueshipotecaPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Remolqueshipoteca remolqueshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into remolqueshipoteca(idremolque,placa,idrecibo,fechahipoteca,identidad,activo,idmunicipio,fecha,username,idreciboliberacion,fechahipotecaliberacion,idremolqueshipoteca)  values(?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setLong(1,remolqueshipoteca.getIdremolque());
        pinsert.setString(2,remolqueshipoteca.getPlaca());
        pinsert.setInt(3,remolqueshipoteca.getIdrecibo());
        pinsert.setDate(4,remolqueshipoteca.getFechahipoteca());
        pinsert.setInt(5,remolqueshipoteca.getIdentidad());
        pinsert.setString(6,remolqueshipoteca.getActivo());
        pinsert.setString(7,remolqueshipoteca.getIdmunicipio());
        pinsert.setDate(8,remolqueshipoteca.getFecha());
        pinsert.setString(9,remolqueshipoteca.getUsername());
        pinsert.setInt(10,remolqueshipoteca.getIdreciboliberacion());
        pinsert.setDate(11,remolqueshipoteca.getFechahipotecaliberacion());
        pinsert.setInt(12,remolqueshipoteca.getIdremolqueshipoteca());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Remolqueshipoteca remolqueshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update remolqueshipoteca set  idremolque=?, placa=?, idrecibo=?, fechahipoteca=?, identidad=?, activo=?, idmunicipio=?, fecha=?, username=?, idreciboliberacion=?, fechahipotecaliberacion=?, idremolqueshipoteca=?  where  idremolqueshipoteca ='"+remolqueshipoteca.getIdremolqueshipoteca()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,remolqueshipoteca.getIdremolque());
pupdate.setString(2,remolqueshipoteca.getPlaca());
pupdate.setInt(3,remolqueshipoteca.getIdrecibo());
pupdate.setDate(4,remolqueshipoteca.getFechahipoteca());
pupdate.setInt(5,remolqueshipoteca.getIdentidad());
pupdate.setString(6,remolqueshipoteca.getActivo());
pupdate.setString(7,remolqueshipoteca.getIdmunicipio());
pupdate.setDate(8,remolqueshipoteca.getFecha());
pupdate.setString(9,remolqueshipoteca.getUsername());
pupdate.setInt(10,remolqueshipoteca.getIdreciboliberacion());
pupdate.setDate(11,remolqueshipoteca.getFechahipotecaliberacion());
pupdate.setInt(12,remolqueshipoteca.getIdremolqueshipoteca());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  remolqueshipoteca set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Remolqueshipoteca remolqueshipoteca_old , Remolqueshipoteca remolqueshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update remolqueshipoteca set  idremolqueshipoteca=?  where  idremolqueshipoteca ='"+remolqueshipoteca_old.getIdremolqueshipoteca()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(12,remolqueshipoteca.getIdremolqueshipoteca());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Remolqueshipoteca remolqueshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolqueshipoteca  where  idremolqueshipoteca = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(12,remolqueshipoteca.getIdremolqueshipoteca());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolqueshipoteca where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolqueshipoteca  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Remolqueshipoteca remolqueshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from remolqueshipoteca where idremolqueshipoteca='"+remolqueshipoteca.getIdremolqueshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Remolqueshipoteca findByPrimaryKey(Remolqueshipoteca remolqueshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from remolqueshipoteca where idremolqueshipoteca='"+remolqueshipoteca.getIdremolqueshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            remolqueshipoteca.setIdremolque(rs.getLong("idremolque"));
remolqueshipoteca.setPlaca(rs.getString("placa"));
remolqueshipoteca.setIdrecibo(rs.getInt("idrecibo"));
remolqueshipoteca.setFechahipoteca(rs.getDate("fechahipoteca"));
remolqueshipoteca.setIdentidad(rs.getInt("identidad"));
remolqueshipoteca.setActivo(rs.getString("activo"));
remolqueshipoteca.setIdmunicipio(rs.getString("idmunicipio"));
remolqueshipoteca.setFecha(rs.getDate("fecha"));
remolqueshipoteca.setUsername(rs.getString("username"));
remolqueshipoteca.setIdreciboliberacion(rs.getInt("idreciboliberacion"));
remolqueshipoteca.setFechahipotecaliberacion(rs.getDate("fechahipotecaliberacion"));
remolqueshipoteca.setIdremolqueshipoteca(rs.getInt("idremolqueshipoteca"));
    }
    rs.close();
    psquery.close();
 return remolqueshipoteca;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdremolque()
*/

public static List<Remolqueshipoteca> findByIdremolque(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where idremolque='"+remolqueshipoteca.getIdremolque()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPlaca()
*/

public static List<Remolqueshipoteca> findByPlaca(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where placa='"+remolqueshipoteca.getPlaca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdrecibo()
*/

public static List<Remolqueshipoteca> findByIdrecibo(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where idrecibo='"+remolqueshipoteca.getIdrecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechahipoteca()
*/

public static List<Remolqueshipoteca> findByFechahipoteca(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where fechahipoteca='"+remolqueshipoteca.getFechahipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdentidad()
*/

public static List<Remolqueshipoteca> findByIdentidad(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where identidad='"+remolqueshipoteca.getIdentidad()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Remolqueshipoteca> findByActivo(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where activo='"+remolqueshipoteca.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Remolqueshipoteca> findByIdmunicipio(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where idmunicipio='"+remolqueshipoteca.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Remolqueshipoteca> findByFecha(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where fecha='"+remolqueshipoteca.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUsername()
*/

public static List<Remolqueshipoteca> findByUsername(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where username='"+remolqueshipoteca.getUsername()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdreciboliberacion()
*/

public static List<Remolqueshipoteca> findByIdreciboliberacion(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where idreciboliberacion='"+remolqueshipoteca.getIdreciboliberacion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechahipotecaliberacion()
*/

public static List<Remolqueshipoteca> findByFechahipotecaliberacion(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where fechahipotecaliberacion='"+remolqueshipoteca.getFechahipotecaliberacion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdremolqueshipoteca()
*/

public static List<Remolqueshipoteca> findByIdremolqueshipoteca(Remolqueshipoteca remolqueshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
      String sql = "select * from remolqueshipoteca where idremolqueshipoteca='"+remolqueshipoteca.getIdremolqueshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Remolqueshipoteca> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolqueshipoteca>();
  String sql = "select * from remolqueshipoteca";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from remolqueshipoteca";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from remolqueshipoteca where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from remolqueshipoteca";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from remolqueshipoteca where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Remolqueshipoteca> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Remolqueshipoteca>();
  String sql = "select * from remolqueshipoteca where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Remolqueshipoteca> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Remolqueshipoteca>();
  String sql = "select * from remolqueshipoteca";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolqueshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Remolqueshipoteca remolqueshipoteca2 = new Remolqueshipoteca(
         rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idremolqueshipoteca"));
            
            
       list.add(remolqueshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
